package per.ace.validate.config;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @program: springbootDemo
 * @description: 定义通用的数据返回对象
 * @author: ace
 * @Date: 2020-06-12 13:42
 */
@Data
@ToString
@NoArgsConstructor
public class GlobalResponse<T> {

    private T data;
    protected boolean success = false;
    private Integer errorCode;
    private String errorMsg;

    public GlobalResponse(T data, boolean success) {
        this.data = data;
        this.success = success;
    }

    public static <T> GlobalResponse<T> success(T data){
        return new GlobalResponse<>(data , true);
    }

    public static <T> GlobalResponse<T> fail(String errorMsg , Integer errorCode){
        GlobalResponse<T> response = new GlobalResponse<T>();
        response.setErrorMsg(errorMsg);
        response.setErrorCode(errorCode);
        response.setSuccess(false);
        return response;
    }
}
